<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        span {
            color: #aaa;
            font-size: 14px;
        }
        
        .red {
            color: red;
        }
        
        .green {
            color: green;
        }
    </style>
</head>

<body>
    <input type="text" name="" id="" class="uname"><span>请输入用户名</span>
    <script>
        //  \s
        // 匹配空白字符；

        // \S
        // 匹配非空白字符；
        var reg = /^[\u4E00-\u9FA5a-zA-Z0-9_-]{6,16}$/;
        var uname = document.querySelector('.uname');
        var sp = document.querySelector('span');
        uname.onblur = function() {
            if (reg.test(this.value)) {
                console.log('正确的');
                sp.className = 'green';
                sp.innerHTML = '用户名输入正确';
            } else {
                sp.className = 'red';
                sp.innerHTML = '用户名输入错误';
            }
        }
    </script>
</body>

</html>